package com.ruicar.afs.cloud.afscase.mq.receiver.processor;

import com.ruicar.afs.cloud.afscase.loanactivatepool.service.LoanActivateService;
import com.ruicar.afs.cloud.common.modules.dto.mq.loan.LoanDiscardDTO;
import com.ruicar.afs.cloud.common.mq.rabbit.listener.AfsMqBizProcessor;
import com.ruicar.afs.cloud.common.mq.rabbit.message.MqTransCode;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;

/**
 * <p>Description：合作商废弃合同申请</p>
 * @author rongji.zhang
 * @createDate 2020-8-30
 * @version 1.0
 * */
@AllArgsConstructor
@Slf4j
@Component
@ConditionalOnProperty(prefix = "com.ruicar.afs.cloud.mq.rabbit",name="enable")
public class LoanDiscardProcessor implements AfsMqBizProcessor<LoanDiscardDTO> {

    private LoanActivateService loanActivateService;
    /**
     * Process message boolean
     *
     * @param entity afs trans entity
     * @return the boolean
     * @throws Exception exception
     */
    @Override
    public boolean processMessage(LoanDiscardDTO entity) throws Exception {
        if(entity.getOperationType().equals("cancel")){
            try {
                loanActivateService.discardCase(entity);
                log.info("合作商取消合同申请消息接收成功");
                return true;
            }catch (Exception e){
                log.info("合作商取消合同申请消息接收失败");
                return false;
            }
        } else if(entity.getOperationType().equals("back")){
            try {
                loanActivateService.backCase(entity.getContractNo(),entity.getStatus());
                log.info("合作商撤回合同申请消息接收成功");
                return true;
            }catch (Exception e){
                log.info("合作商撤回合同申请消息接收失败");
                return false;
            }
        } else {
            log.info("无此操作！");
            return false;
        }
    }

    /**
     * Gets code *
     *
     * @return the code
     */
    @Override
    public MqTransCode getCode() { return  MqTransCode.AFS_POS_APPLY_CASE_CTM_DISCARD_LOAN; }
}
